package com.yauthor.module
{
	import flexunit.framework.TestCase;

	public class ResultTest extends TestCase{
		
		protected var m_state:ComponentState;
		
		public function ResultTest(methodName:String = null){
			super(methodName);
		}
		
		public function testSaveState():void{
			var result:Result;
			var childResult:Result;
			
			//test simple result with includeErrorsInResult set to true
			result = saveAndLoadState(new Result(3, 1, 1));
			
			assertEquals("simple result, todo", result.todo, 3);
			assertEquals("simple result, done", result.done, 1);
			assertEquals("simple result, errors", result.errors, 1);
			assertEquals("simple result, errorsInResult", result.errorsInResult, 1);
			assertEquals("simple result, result", result.result, 0);
			assertTrue("simple result, includeErrorsInResult", result.includeErrorsInResult);
			assertFalse("simple result, evaluationPending", result.evaluationPending);
			
			//test simple result with includeErrorsInResult set to false
			result = saveAndLoadState(new Result(3, 1, 1, false));
			
			assertEquals("simple result, false, todo", result.todo, 3);
			assertEquals("simple result, false, done", result.done, 1);
			assertEquals("simple result, false, errors", result.errors, 1);
			assertEquals("simple result, false, errorsInResult", result.errorsInResult, 0);
			assertEquals("simple result, false, result", result.result, 33);
			assertFalse("simple result, false, includeErrorsInResult", result.includeErrorsInResult);
			assertFalse("simple result, false, evaluationPending", result.evaluationPending);	
			
			//test appended result
			result = new Result(4, 2, 1);
			result.append(new Result(3, 1, 1, false)); 	
			result = saveAndLoadState(result);
			
			assertEquals("appended result, false, todo", result.todo, 7);
			assertEquals("appended result, false, done", result.done, 3);
			assertEquals("appended result, false, errors", result.errors, 2);
			assertEquals("appended result, false, errorsInResult", result.errorsInResult, 1);
			assertEquals("appended result, false, result", result.result, 28);
			assertTrue("appended result, false, includeErrorsInResult", result.includeErrorsInResult);
			assertFalse("appended result, false, evaluationPending", result.evaluationPending);
		}
		
		private function saveAndLoadState(res:Result):Result{
			saveState(res);
			return loadState();
		}
		
		private function loadState():Result{
			var result:Result = new Result();
			
			m_state.prepareStateLoad()
			m_state.loadChildState(result);
			
			return result;			
		}
		
		private function saveState(res:Result):void{
			m_state = new ComponentState();
			m_state.prepareStateSave();
			m_state.saveChildState(res);
		}
	}
}